/*
 * ImagesMng.h
 *
 *  Created on: 28.01.2010
 *      Author: Admin
 */

#ifndef IMAGESMNG_H_
#define IMAGESMNG_H_

#include <string>
#include <vector>
#include <sys/types.h>

#define PNG_DEBUG 3
#include <png.h>
extern "C"{
#include <jpeglib.h>
}
#include "inkview.h"
#include "Log.h"

class ImagesMng
{
private:
	ibitmap* _prev_img;
	ibitmap* _current_img;
	ibitmap* _next_img;

	std::string _dir;
	std::vector<std::string> _files;
	int _current_index;

	ibitmap* OpenBMP(char* filename);
	ibitmap* OpenJPEG(char* filename);
	ibitmap* OpenPNG(char* filename);

	ibitmap* OpenFile(std::string filename);
	std::string GetFileExtension(std::string path);
	void ClearBuffers();

/*
	int _archive_type;
	std::string unrar_path;
	std::string unzip_path;
	enum supported_archives { UNSUPPORTED, TAR, TGZ, TBZ2, ZIP, RAR };
	int GetArchiveType(std::string path);
	bool HasSuffix(const char *path, const char *suf);
	std::string UnpackArchiveToDir(std::string dir, std::string filename);
*/

public:
	ImagesMng();
	~ImagesMng();

	void Open(std::string path, std::string filename);
	void Open(std::string fullname);

	ibitmap* Current(){return _current_img;}
	ibitmap* Next();
	ibitmap* Prev();
	ibitmap* GoTo(int index);
	ibitmap* First(){return GoTo(0);}
	ibitmap* Last(){return GoTo(_files.size()-1);}
	bool HasNext(){return _current_index < (int)_files.size()-1;}
	bool HasPrev(){return _current_index > 0;}
	bool IsBuffered();
	void Buffering();

	std::string GetDirectory(){return _dir;}
	unsigned int GetFilesCount(){return _files.size();}
	int GetCurrentFileIndex(){return _current_index;}
	std::string GetFileName(size_t index);
	std::string GetFileFullame(size_t index);
	std::string GetCurrentFileName(){return GetFileName(_current_index);}
	std::string GetCurrentFileFullname(){return GetFileFullame(_current_index);}
	ibitmap* GetImage(size_t index);

/*
	bool IsSupportedArchive(std::string path);
	int DeleteUnpackedArchive();
	void SetUnrarPath(char *path){unrar_path = path;}
	void SetUnzipPath(char *path){unzip_path = path;}
*/

};

#endif /* IMAGESMNG_H_ */
